package com.f5.management.controller;

import com.f5.management.entity.Community;
import com.f5.management.entity.Equipment;
import com.f5.management.service.EquipmentService;
import com.f5.management.utils.PageResult;
import com.f5.management.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;

@RestController
@RequestMapping("/equipment")
@CrossOrigin(origins = {"http://localhost:8080", "null"})
public class EquipmentController {

    @Autowired
    private EquipmentService equipmentService;

    @RequestMapping("/findByPage")
    public PageResult<List<Equipment>> findByPage(int page, int size) {

        return equipmentService.findByPage(page, size);
    }
    @RequestMapping("/add")
    public ResponseResult<String> add(Equipment equipment) throws ParseException {

        return new ResponseResult<String>(equipmentService.add(equipment));
    }
    @RequestMapping("/findCidByName")
    public  int findCidByName(String communityName){

        return equipmentService.findCidByName(communityName);
    }
    @RequestMapping("/findById")
    public  Equipment findById(int id){

        System.out.println(equipmentService.findById(id));

        return equipmentService.findById(id);
    }
    @RequestMapping("/updateInfo")
    public ResponseResult<String> updateInfo(Equipment equipment) {

        System.out.println("11111111111111111111");
        System.out.println(equipmentService.updateInfo(equipment));

        return new ResponseResult<String>(equipmentService.updateInfo(equipment));

    }
    @RequestMapping("/delInfo")
    public ResponseResult<String> delInfo(int id) {

        return new ResponseResult<String>(equipmentService.delInfo(id));

    }


}
